home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac-Source 1994 July
/
Mac-Source_July_1994.iso
/
C and C++
/
Libraries
/
usr (gcc 1.37 libs)
/
mac
/
close.c
< prev
next >
Wrap
C/C++ Source or Header
|
1993-12-08
|
735b
|
41 lines
#include <sys/types.h>
#include <sys/syslimits.h>
#include <fcntl.h>
#include "crtlocal.h"
int close(int fd)
{
int res = -1;
short refnum = crt_fd_tab[fd].fd;
int i;
mysleep(1);
if (crt_fd_tab[fd].flags & O_PIPE)
{
crt_fd_tab[fd].flags = 0;
refnum = 0;
}
for (i = 0; i < OPEN_MAX; i++)
if ((i != fd) && (refnum == crt_fd_tab[i].fd)) res = i;
if ((res == -1) && refnum)
{
FCBPBRec pb;
pb.ioRefNum = refnum;
pb.ioCompletion = 0;
pb.ioVRefNum = crt_ioVRefNum;
PBCloseSync((ParmBlkPtr)&pb);
res = pb.ioResult;
}
else res = refnum;
crt_fd_tab[fd].fd = 0;
return res;
}
void closeall(void)
{
int i;
for (i = 0; i < OPEN_MAX; i++)
{
if (crt_fd_tab[i].fd) close(crt_fd_tab[i].fd);
}
}